//
//  ErrorTipView.m
//  DabaiInsurance
//
//  Created by menchao on 16/7/29.
//  Copyright © 2016年 menchao. All rights reserved.
//

#import "ErrorTipView.h"
#import "PlatformMacro.h"

@interface ErrorTipView ()

@property (nonatomic,copy) TapAction tapAction;


@end


@implementation ErrorTipView


- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    UIView *errorView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    
    self.backgroundColor = [UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1];
   // errorView.backgroundColor = [UIColor clearColor];

    
    [self addSubview:errorView];
 
    CGFloat errorViewHeight = 100+20+20+48+30;
    CGFloat startY =  (self.bounds.size.height -  errorViewHeight -100 )/2 ;// (ScreenHeight - errorViewHeight -64)/2 ;

    UIImageView *failImgView = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth/2-50, startY, 100, 100)];
    failImgView.image = [UIImage imageNamed:@"ErrorTip"];
    failImgView.contentMode = UIViewContentModeScaleToFill;
    [errorView addSubview:failImgView];

    startY +=(100 +10);
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, startY, ScreenWidth, 20)];
    label.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    label.font = [UIFont systemFontOfSize:16];
    label.text = @"无可用网络";
    label.textAlignment = NSTextAlignmentCenter;
    [errorView addSubview:label];

//    startY +=(20 +10);
//    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(0, startY, ScreenWidth, 20)];
//    label2.textColor = [UIColor grayColor];
//    label2.font = [UIFont systemFontOfSize:15];
//    label2.text = @"请检查您的网络重新加载吧";
//    label2.textAlignment = NSTextAlignmentCenter;
//    [errorView addSubview:label2];
    
    startY +=(20 +15);
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-50, startY, 100, 30)];
    [btn setTitle:@"重新加载" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:15.0];
    [btn setTitleColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1] forState:UIControlStateNormal];
    btn.layer.cornerRadius = 4;
    btn.layer.borderWidth = 0.5;
    btn.layer.borderColor = [UIColor colorWithRed:179/255.0 green:179/255.0 blue:179/255.0 alpha:1].CGColor;
    btn.layer.masksToBounds = YES;
    [btn addTarget:self action:@selector(errorTap) forControlEvents:UIControlEventTouchUpInside];
    [errorView addSubview:btn];

}


- (void)errorTap {
    if (_tapAction) {
        _tapAction();
    }
    _tapAction = nil;
}

- (void)tapAction:(TapAction)block{
    _tapAction = block;
}


//- (UIView *)errorView {
//    
//    if (_errorView == nil) {
//        UIView *errorView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64)];
//        errorView.backgroundColor = [UIColor greenColor];
//        [self.view addSubview:errorView];
//        //        [errorView mas_makeConstraints:^(MASConstraintMaker *make) {
//        //            make.edges.equalTo(self.container);
//        //        }];
//        
//        UIImageView *failImgView = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth/2-50, 120, 100, 100)];
//        failImgView.image = [UIImage imageNamed:@"netFailIcon"];
//        [errorView addSubview:failImgView];
//        //        [failImgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        //            make.centerX.equalTo(errorView);
//        //            make.centerY.equalTo(errorView).offset(-80);
//        //            make.width.equalTo(@120);
//        //            make.height.equalTo(@120);
//        //        }];
//        
//        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2-100, 240, 200, 40)];
//        label.textColor = [UIColor grayColor];
//        label.font = [UIFont systemFontOfSize:17];
//        label.text = @"网络请求失败";
//        label.textAlignment = NSTextAlignmentCenter;
//        [errorView addSubview:label];
//        _errorLab = label;
//        //        [label mas_makeConstraints:^(MASConstraintMaker *make) {
//        //            make.top.equalTo(failImgView.mas_bottom).offset(25);
//        //            make.centerX.equalTo(errorView);
//        //        }];
//        
//        UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2-100, 300, 200, 40)];
//        label2.textColor = [UIColor grayColor];
//        label2.font = [UIFont systemFontOfSize:15];
//        label2.text = @"请检查您的网络重新加载吧";
//        label2.textAlignment = NSTextAlignmentCenter;
//        [errorView addSubview:label2];
//        //        [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        //            make.top.equalTo(label.mas_bottom).offset(10);
//        //            make.centerX.equalTo(errorView);
//        //        }];
//        
//        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-75, 350, 150, 60)];
//        [btn setTitle:@"重新加载" forState:UIControlStateNormal];
//        btn.backgroundColor = [UIColor clearColor];
//        btn.layer.cornerRadius = 5;
//        btn.layer.borderWidth = 0.5;
//        btn.layer.borderColor = [UIColor lightGrayColor].CGColor;
//        btn.layer.masksToBounds = YES;
//        [btn addTarget:self action:@selector(errorTap) forControlEvents:UIControlEventTouchUpInside];
//        [errorView addSubview:btn];
//        //        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
//        //            make.top.equalTo(label2.mas_bottom).offset(35);
//        //            make.width.mas_equalTo(120);
//        //            make.height.mas_equalTo(40);
//        //            make.centerX.equalTo(errorView);
//        //        }];
//        
//        _errorView = errorView;
//    }
//    
//    return _errorView;
//}
//


@end
